<?php
class Controller_Setting_Log extends Controller_Abstract
{
	function actionEbayApiCallLogList()
	{
		$this->_view['title'] = 'ebay请求日志列表';
		$cp = isset($_GET['cp']) ? $_GET['cp'] : 0;
		$ps = isset($_GET['ps']) ? $_GET['ps'] : 20;
		$users = User::find('status=?', Q::ini('custom_flag/user_status/on_duty/value'))->order('name asc')->asArray()->getAll();
		$this->_view['users'] = $users;
		$url_arr = Helper_BSS_Normal::buildCondition();
		$result = Ebay_Api_Call_Log::search($url_arr, $cp, $ps);
		if ($result['ack'] == SUCCESS)
		{
			$page = new Helper_BSS_Page($result['pagination'], url('Setting::Log/EbayApiCallLogList', $url_arr));
			$this->_view['page'] = $page->getPage();
			$this->_view['ebay_api_call_log_lists'] = $result['data'];
		}
	}
	
	function actionEbayApiCallLogFile()
	{
		$this->_view['title'] = 'ebay请求日志文件';
		$dir = Q::ini('custom_system/ebay_api_call_log_dir') . $_GET['filename'];
		if (file_exists($dir))
		{
			$xml = file_get_contents($dir);
			header('Content-Type: text/xml');
			echo($xml);
			exit;
		}
		else
		{
			return $this->_redirectMessage('文件打开失败！', '文件不存在！', $_SERVER['HTTP_REFERER'], FAILURE);
		}
	}
	
	function actionMarkStatusCompleted()
	{
		$this->_view['title'] = '标记完成';
		if ($this->_context->isGET())
		{
			$ebay_api_call_log_ids = explode(',', $_GET['ids']);
			$result = Ebay_Api_Call_Log::markStatusCompleted($ebay_api_call_log_ids);
			if ($result['ack'] == SUCCESS)
			{
				return $this->_redirectMessage('标记完成成功', '正在返回..', $_SERVER['HTTP_REFERER'], $result['ack']);
			}
			else
			{
				return $this->_redirectMessage('标记完成失败', $result['message'], $_SERVER['HTTP_REFERER'], $result['ack']);
			}
		}
	}
}